﻿#ifndef __SPI_FLASH_H
#define __SPI_FLASH_H


#include <nrf.h>

#define SPI_INSTANCE  0                                                             /**< SPI instance index. */

extern uint8_t spim_buffer[266];
extern uint8_t spim_rxbuf[260];

void SPI_FLASH_Init(void);
void SPI_FLASH_SectorErase(uint32_t SectorAddr);
void SPI_FLASH_Erase_Block(uint32_t nDest);
void SPI_FLASH_BulkErase(void);
void SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite,uint8_t offset);
void SPI_FLASH_PageRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead, uint8_t offset);
void SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
void SPI_FLASH_Read_Sector(uint32_t nSector, uint8_t* pBuffer,uint16_t length);
void SPI_FLASH_Erase_Sector(uint32_t nDest);
void SPI_FLASH_Write_Sector(uint32_t nSector, uint8_t* pBuffer,uint16_t length);


void SPI_FLASH_Read_Sector_Ex(uint32_t nSector, uint8_t* pBuffer,uint16_t length,uint16_t offset);
void SPI_FLASH_Write_Sector_Ex(uint32_t nSector, uint8_t* pBuffer,uint16_t length,uint16_t offset);

uint32_t SPI_FLASH_ReadID(void);
uint32_t SPI_FLASH_ReadDeviceID(void);
void SPI_FLASH_StartReadSequence(uint32_t ReadAddr);
void SPI_Flash_PowerDown(void);
void SPI_Flash_WAKEUP(void);


uint8_t SPI_FLASH_ReadByte(void);
uint8_t SPI_FLASH_SendByte(uint8_t byte);
uint16_t SPI_FLASH_SendHalfWord(uint16_t HalfWord);
void SPI_FLASH_WriteEnable(void);
void SPI_FLASH_WaitForWriteEnd(void);

void spim_init(void);
uint32_t spi_flash_init(void);
void spi_flash_uninit(void);



/*  实现w25r的spi读接口    */
//extern int spi_flash_read(uint32_t addr, uint8_t *data, uint32_t len);

#endif /* __SPI_FLASH_H */

